package com.elai.operate.controller;

import java.util.List;

import com.elai.common.annotation.Log;
import com.elai.common.core.controller.BaseController;
import com.elai.common.core.domain.AjaxResult;
import com.elai.common.core.page.TableDataInfo;
import com.elai.common.enums.BusinessType;
import com.elai.common.utils.poi.ExcelUtil;
import com.elai.operate.domain.OperateReferrerDO;
import com.elai.operate.service.OperateReferrerService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 只能推荐Controller
 *
 * @author elai
 * @date 2021-04-04
 */
@RestController
@RequestMapping("/operate/referrer")
public class OperateReferrerController extends BaseController
{
    @Autowired
    private OperateReferrerService operateReferrerService;

    /**
     * 查询只能推荐列表
     */
    @PreAuthorize("@ss.hasPermi('operate:referrer:list')")
    @GetMapping("/list")
    public TableDataInfo list(OperateReferrerDO operateReferrer)
    {
        startPage();
        List<OperateReferrerDO> list = operateReferrerService.selectOperateReferrerList(operateReferrer);
        return getDataTable(list);
    }

    /**
     * 导出只能推荐列表
     */
    @PreAuthorize("@ss.hasPermi('operate:referrer:export')")
    @Log(title = "只能推荐", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OperateReferrerDO operateReferrer)
    {
        List<OperateReferrerDO> list = operateReferrerService.selectOperateReferrerList(operateReferrer);
        ExcelUtil<OperateReferrerDO> util = new ExcelUtil<OperateReferrerDO>(OperateReferrerDO.class);
        return util.exportExcel(list, "referrer");
    }

    /**
     * 获取只能推荐详细信息
     */
    @PreAuthorize("@ss.hasPermi('operate:referrer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(operateReferrerService.selectOperateReferrerById(id));
    }

    /**
     * 新增只能推荐
     */
    @PreAuthorize("@ss.hasPermi('operate:referrer:add')")
    @Log(title = "只能推荐", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OperateReferrerDO operateReferrer)
    {
        return toAjax(operateReferrerService.insertOperateReferrer(operateReferrer));
    }

    /**
     * 修改只能推荐
     */
    @PreAuthorize("@ss.hasPermi('operate:referrer:edit')")
    @Log(title = "只能推荐", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OperateReferrerDO operateReferrer)
    {
        return toAjax(operateReferrerService.updateOperateReferrer(operateReferrer));
    }

    /**
     * 删除只能推荐
     */
    @PreAuthorize("@ss.hasPermi('operate:referrer:remove')")
    @Log(title = "只能推荐", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(operateReferrerService.deleteOperateReferrerByIds(ids));
    }
}
